package com.redshark.wmm.UI;

import com.redshark.wmm.R;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;

public class ButtonFragment extends Fragment implements OnClickListener{
	public final static int BTN_DC_VOLTAGE = 1;
	public final static int BTN_DC_CURRENT = 2;
	public final static int BTN_RESISTANCE = 3;
	public final static int BTN_SCOPE = 4;
	public final static int BTN_CONNECT = 5;
	public final static int BTN_FREQUENCY = 6;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
        // retain this fragment
        setRetainInstance(true);

		super.onCreate(savedInstanceState);
	}
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.button_fragment_layout, container, true);
        
        ImageButton b1 = (ImageButton) v.findViewById(R.id.button1);
        b1.setOnClickListener(this);
        
        ImageButton b2 = (ImageButton) v.findViewById(R.id.button2);
        b2.setOnClickListener(this);
        
        ImageButton b3 = (ImageButton) v.findViewById(R.id.button3);
        b3.setOnClickListener(this);
        
        ImageButton b4 = (ImageButton) v.findViewById(R.id.button4);
        b4.setOnClickListener(this);
        
        ImageButton b5 = (ImageButton) v.findViewById(R.id.button5);
        b5.setOnClickListener(this);
        
        ImageButton b6 = (ImageButton) v.findViewById(R.id.button6);
        b6.setOnClickListener(this);
        
        ImageButton b7 = (ImageButton) v.findViewById(R.id.button7);
        b7.setOnClickListener(this);
        
        ImageButton b8 = (ImageButton) v.findViewById(R.id.button8);
        b8.setOnClickListener(this);
        
        return v;
    }
    
    @Override
    public void onClick(View v){
		MainActivity a = (MainActivity)getActivity();
		
    	switch(v.getId()){
    	case R.id.button1:
    		a.onButtonClick(R.id.button1);
    		break;
    	case R.id.button2:
    		a.onButtonClick(R.id.button2);
    		break;
    	case R.id.button3:
    		a.onButtonClick(R.id.button3);
    		break;
    	case R.id.button4:
    		a.onButtonClick(R.id.button4);
    		break;
    	case R.id.button5:
    		a.onButtonClick(R.id.button5);
    		break;
    	case R.id.button6:
    		a.onButtonClick(R.id.button6);
    		break;
    	case R.id.button7:
    		a.onButtonClick(R.id.button7);
    		break;
    	case R.id.button8:
    		a.onButtonClick(R.id.button8);
    		break;
    	}
    }
	
	public void buttonsEnabled(boolean enabled){
		((View) getView().findViewById(R.id.button1)).setEnabled(enabled);
		((View) getView().findViewById(R.id.button2)).setEnabled(enabled);
		((View) getView().findViewById(R.id.button3)).setEnabled(enabled);
		((View) getView().findViewById(R.id.button4)).setEnabled(enabled);
		((View) getView().findViewById(R.id.button5)).setEnabled(enabled);
		((View) getView().findViewById(R.id.button6)).setEnabled(enabled);
		((View) getView().findViewById(R.id.button7)).setEnabled(enabled);
		((View) getView().findViewById(R.id.button8)).setEnabled(enabled);
	}

}
